const {createProxyMiddleware: proxy} = require('http-proxy-middleware')

module.exports = function(app) {
  app.use(

    proxy('/api1',{         // api1是需要转发的请求(所有带有/api前缀的请求都转发到 5000)
      target: 'http://localhost:5000',
      changeOrigin: true,
      pathRewrite: {'^/api1': ''}
    }),

    
    proxy('/api2',{
        target: 'http://localhost:5001',
        changeOrigin: true,
        pathRewrite: {'^/api2': ''}     // 重新请求路径,将 /api2 替换为空字符串即去掉 /api2
    }),

  )
}